<?php
function vpost($url,$data){ // ģ���ύ���ݺ���  
    $curl = curl_init(); // ���һ��CURL�Ự  
    curl_setopt($curl, CURLOPT_URL, $url); // Ҫ���ʵĵ�ַ  
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // ����֤֤����Դ�ļ��  
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // ��֤���м��SSL�����㷨�Ƿ����  
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // ģ���û�ʹ�õ������  
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // ʹ���Զ���ת  
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // �Զ�����Referer  
    curl_setopt($curl, CURLOPT_POST, 1); // ����һ�������Post����  
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post�ύ�����ݰ�  
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // ���ó�ʱ���Ʒ�ֹ��ѭ��  
    curl_setopt($curl, CURLOPT_HEADER, 0); // ��ʾ���ص�Header��������  
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // ��ȡ����Ϣ���ļ�������ʽ����  
    $tmpInfo = curl_exec($curl); // ִ�в���  
    if (curl_errno($curl)) {  
       echo 'Errno'.curl_error($curl);//��ץ�쳣  
    }  
    curl_close($curl); // �ر�CURL�Ự  
    return $tmpInfo; // ��������  
}  
  
//echo getSqlStockCode();

  
$url = "https://gupiao.baidu.com/api/rails/stockbasicbatch";  
//$data ="from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=usAAPL,usGOOG,usMSFT,usAMZN,hk00700,usFB,usBABA,usBRK.A,usJNJ,usXOM,usJPM,sh601398,usWMT,usTSM,usTM,usKO,usIBM,usMCD,sh600519,usBIDU,usJD,sz002024&timestamp=".intval(time());;  

$data ="from=pc&os_ver=1&cuid=xxx&vv=100&format=json&stock_code=".getSqlStockCode()."&timestamp=".intval(time());

$result = vpost($url,$data);




echo $result;

function getSqlStockCode(){
    $codes="";
$mysql_server_name='localhost'; //改成自己的mysql数据库服务器
 
$mysql_username='root'; //改成自己的mysql数据库用户名
 
$mysql_password='drc123'; //改成自己的mysql数据库密码
 
$mysql_database='test'; //改成自己的mysql数据库名
    $conn=mysqli_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database); //连接数据库
 
//mysqli_query("set names 'utf8'"); //数据库输出编码 应该与你的数据库编码保持一致.南昌网站建设公司百恒网络PHP工程师建议用UTF-8 国际标准编码.
 
//mysqli_select_db($mysql_database); //打开数据库
 
$sql ="select code from stockCode where 1=1 order by value*1 desc "; //SQL语句
 
$result = mysqli_query($conn,$sql); //查询
//mysqli_close(); //关闭MySQL连接
  while($row = mysqli_fetch_array($result))
 
{
 
if($codes!=""){
    $codes= $codes.",".$row['code'] ;
}else{
    $codes=$row['code'];
}

}  

    return $codes;
}


?>